#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <list>
#include <queue>
#include <iostream>
#include <limits>
#include <string>
using namespace std;
#define forr(a, b) for (int a = 0; a < b; ++a)
#define eps 1e-9
#define inf 1e9
#define pb push_back


typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vint;
template<class T>  T gcd(T a, T b){return b?gcd(b,a%b):a;}
int main(){
    //freopen("input.txt","r", stdin);
    map<string,int> td;
    int cnt;
    td["void"]=0;
    cin>>cnt;
    forr(cnttt,cnt){
        string a,b,c;
        cin>>a;
        if (a=="typedef"){
            cin>>b>>c;
            int beg=0,end=b.length()-1;
            while(b[beg]=='&')++beg;
            while(b[end]=='*')--end;
            if (beg>end){
                continue;
            }
            string x;
            for(int i=beg;i<=end;++i)
                x+=b[i];
            if(!(td.find(x)!=td.end())){
                td[c]=-1;
                continue;
            }
            int cur=td[x];
            if (cur<0)
            {
                td[c]=cur;
                continue;
            }
                cur-=beg;
                cur+=(b.length()-1-end);
            td[c]=cur;
        }
        else{
            cin>>b;
            int beg=0,end=b.length()-1;
            while(b[beg]=='&')++beg;
            while(b[end]=='*')--end;
            if (beg>end){
                cout<<"errtype\n";
                continue;
            }
            string x;
            for(int i=beg;i<=end;++i)
                x+=b[i];
            if(!(td.find(x)!=td.end()))
                cout<<"errtype\n";
            else{
                int cur=td[x];
                if (cur<0){
                    cout<<"errtype\n";
                    continue;
                }
                cur-=beg;
                cur+=(b.length()-1-end);
                if (cur<0)
                    cout<<"errtype\n";
                else {cout<<"void";
                for(int i=1;i<=cur;++i)
                    cout<<"*";
                cout<<endl;
                }
            }
        }
    }
    return 0;
}